<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="10" :lg="11" :md="12" :sm="24">
            <a-form-item :label="$t('订单时间')">
              <a-date-picker
                :show-time="{ defaultValue: moment('00:00:00', 'HH:mm:ss') }"
                valueFormat="YYYY-MM-DD HH:mm:ss"
                dateFormat="YYYY-MM-DD HH:mm:ss"
                :placeholder="$t('请选择开始时间')"
                class="query-group-cust"
                v-model="queryParam.createTime_begin"
              ></a-date-picker>
              <span class="query-group-split-cust"></span>
              <a-date-picker
                :show-time="{ defaultValue: moment('23:59:59', 'HH:mm:ss') }"
                valueFormat="YYYY-MM-DD HH:mm:ss"
                dateFormat="YYYY-MM-DD HH:mm:ss"
                :placeholder="$t('请选择结束时间')"
                class="query-group-cust"
                v-model="queryParam.createTime_end"
              ></a-date-picker>
            </a-form-item>
          </a-col>
          <a-col :xl="5" :lg="6" :md="7" :sm="24">
            <a-form-item :label="$t('支付方式')">
              <a-select v-model="queryParam.payType">
                <a-select-option :value="item.name" :key="index" v-for="(item, index) in paytypeList">{{
                  item.nameText
                }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item :label="$t('会员信息')">
                <a-input :placeholder="$t('请输入手机号/卡号/姓名/邮箱')" v-model="queryParam.memberInfo"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item :label="$t('订单状态')">
                <a-select v-model="queryParam.state">
                  <a-select-option :value="item.value" :key="index" v-for="(item, index) in orderstateList">{{
                    item.title
                  }}</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item :label="$t('业务渠道')">
                <a-select v-model="queryParam.deviceType">
                  <a-select-option :value="item.value" :key="index" v-for="(item, index) in deviceinfoList">{{
                    item.title
                  }}</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item :label="$t('设备名称(编码)')">
                <a-select show-search :filter-option="false" @search="handleSearch" v-model="queryParam.deviceId">
                  <a-select-option :value="item.id" :key="index" v-for="(item, index) in deviceList">
                    <span>{{ item.name }}</span>
                    <span v-if="item.name != $t('全部')">({{ item.id }})</span>
                  </a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item :label="$t('操作员')">
                <a-select s v-model="queryParam.createBy">
                  <a-select-option :value="item.id" :key="index" v-for="(item, index) in userList">{{
                    item.realname
                  }}</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item :label="$t('订单号')">
                <a-input :placeholder="$t('请输入订单号/关联订单号')" v-model="queryParam.orderInfo"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item :label="$t('订单类型')">
                <a-select v-model="queryParam.orderType">
                  <a-select-option value="0,2,4,8,6,10,11,12">{{ $t('全部') }}</a-select-option>
                  <a-select-option value="0">{{ $t('销售订单') }}</a-select-option>
                  <a-select-option value="2">{{ $t('销售退单') }}</a-select-option>
                  <a-select-option value="4">{{ $t('美团核销') }}</a-select-option>
                  <a-select-option value="8">{{ $t('抖音核销') }}</a-select-option>
                  <a-select-option value="11">{{ $t('快手核销') }}</a-select-option>
                  <a-select-option value="6">{{ $t('会员退币') }}</a-select-option>
                  <a-select-option value="10">{{ $t('会员退票') }}</a-select-option>
                  <a-select-option value="12">{{ $t('抽奖活动') }}</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24" v-if="!tenantid">
              <a-form-item :label="$t('门店')">
                <a-select v-model="queryParam.shopCode">
                  <a-select-option v-for="(item, i) in shops" :key="i" :value="item.value"
                    >{{ item.title }}<span v-if="item.value != ''">（{{ item.value }}）</span></a-select-option
                  >
                </a-select>
              </a-form-item>
            </a-col>
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">{{ $t('查询') }}</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">{{
                $t('重置')
              }}</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? $t('收起') : $t('展开') }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button 
        v-has="'BisOrderController:export'" 
        type="primary" 
        icon="download" 
        :loading="exloading" 
        @click="handleExportXls($t('商品销售订单'))">
        {{ $t('导出')}}
      </a-button>
      <a-popover :title="$t('自定义列')" trigger="click" placement="leftBottom">
        <template slot="content">
          <a-checkbox-group @change="onColSettingsChange" v-model="settingColumns" :defaultValue="settingColumns">
            <a-row style="width: 400px">
              <template v-for="(item, i) in defColumns">
                <template v-if="item.key != 'rowIndex' && item.dataIndex != 'action'">
                  <a-col :span="12" :key="i"><a-checkbox :value="item.dataIndex"><j-ellipsis :value="item.title"
                        :length="10"></j-ellipsis></a-checkbox></a-col>
                </template>
              </template>
            </a-row>
          </a-checkbox-group>
        </template>
        <a-button type="setting">{{ $t('设置显示项') }}</a-button>
      </a-popover>
      <a-popconfirm v-has="'BisOrderController:delete'" :okText="$t('继续删除')"
        :title="$t('一旦删除将不可恢复，且此操作会把与该订单相关联的其它明细记录【商品销售明细、支付订单、会员业务明细、实币销售明细】一并删除，为了您的数据完整，请谨慎操作')"
        :visible="visible0"
        @cancel="visible0 = false"
        @confirm="() => deleteBatch()">
        <a-button type="primary" @click="handleClick()">{{ $t('批量删除') }}</a-button>
      </a-popconfirm>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px">
        <i class="anticon anticon-info-circle ant-alert-icon"></i>
        <i18n path="selected-items" tag="span">
          <a place="items" style="font-weight: 600">{{ selectedRowKeys.length }}</a>
        </i18n>
        <a style="margin-left: 24px" @click="onClearSelected">{{ $t('清空') }}</a>
      </div>
      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :scroll="{ x: true, y: tableHeight }"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :customHeaderRow="customHeaderRow"
        :customRow="customRow"
        :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange, columnWidth: 60 }"
        @change="handleTableChange"
      >
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px; font-style: italic">{{ $t('无图片') }}</span>
          <img
            v-else
            :src="getImgView(text)"
            height="25px"
            alt=""
            style="max-width: 80px; font-size: 12px; font-style: italic"
          />
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px; font-style: italic">{{ $t('无文件') }}</span>
          <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">
            {{ $t('下载') }}
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click.stop="showModal(record)">{{ $t('详情') }}</a>
          <span @click.stop.prevent="handleParentClick">
            <a-popconfirm v-has="'BisOrderController:delete'"
              :okText="$t('继续删除')"
              :title="$t('一旦删除将不可恢复，且此操作会把与该订单相关联的其它明细记录【商品销售明细、支付订单、会员业务明细、实币销售明细】一并删除，为了您的数据完整，请谨慎操作')"
              @confirm="() => handleDelete(record.id)">
              <a style="margin-left: 7px">{{ $t('删除') }}</a>
            </a-popconfirm>
          </span>
        </span>

        <template slot="footer">
          <div style="font-weight: bold">
            <span style="margin-left: 15px; margin-right: 5px">{{ $t('订单金额') }}：</span>
            <span>{{ totalInfo.price ? totalInfo.price.toFixed(2) : '0.00' }}</span>
            <span style="margin-left: 15px; margin-right: 5px">{{ $t('优惠券抵扣') }}：</span>
            <span>{{ totalInfo.discountAmount ? totalInfo.discountAmount.toFixed(2) : '0.00' }}</span>
            <span style="margin-left: 15px; margin-right: 5px">{{ $t('会员优惠') }}：</span>
            <span>{{ totalInfo.memberDiscount ? totalInfo.memberDiscount.toFixed(2) : '0.00' }}</span>
            <span style="margin-left: 15px; margin-right: 5px">{{ $t('活动优惠') }}：</span>
            <span>{{ totalInfo.activityDiscount ? totalInfo.activityDiscount.toFixed(2) : '0.00' }}</span>
            <span style="margin-left: 15px; margin-right: 5px" v-if="isTax != 0">{{ $t('其中税费') }}：</span>
            <span v-if="isTax != 0">{{ totalInfo.payAmount ? totalInfo.taxPrice.toFixed(2) : '0.00' }}</span>
            <span style="margin-left: 15px; margin-right: 5px">{{ $t('实付金额') }}：</span>
            <span>{{ totalInfo.payAmount ? totalInfo.payAmount.toFixed(2) : '0.00' }}</span>
          </div>
        </template>
      </a-table>
    </div>

    <type-name-modal ref="typeNameForm"></type-name-modal>
    <yarn-cert-out-captcha-modal ref="deleteYarnModal" @ok="handleDeleteCallback"></yarn-cert-out-captcha-modal>
  </a-card>
</template>

<script>
import Vue from 'vue'
import moment from 'moment'
import '@/assets/less/TableExpand.less'
import { getAction, deleteAction } from '@/api/manage'
import { initDictOptions, filterMultiDictText } from '@/components/dict/JDictSelectUtil'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import TypeNameModal from './modules/TypeNameModal'
import YarnCertOutCaptchaModal from '@/views/setting/modules/YarnCertOutCaptchaModal'

export default {
  name: 'OrderList',
  mixins: [JeecgListMixin],
  components: {
    TypeNameModal,
    YarnCertOutCaptchaModal
  },
  data() {
    return {
      description: '商品销售管理页面',
      moment,
      tenantid: Vue.ls.get('TENANT_ID'),
      queryParam: {
        payType: '',
        orderInfo: '',
        state: '2',
        deviceType: '',
        deviceId: '',
        createBy: '',
        orderType: '0,2,4,8,6,10,11,12',
        shopCode: '',
      },
      //列设置
      settingColumns: [],
      // 表头
      columns: [],
      // 表头
      defColumns: [
        {
          title: this.$t('订单号'),
          align: 'center',
          sorter: true,
          dataIndex: 'id',
          width: 170,
        },
        {
          title: this.$t('订单时间'),
          align: 'center',
          sorter: true,
          dataIndex: 'createTime',
          width: 150,
          customCell: (r, i) => {
            return {
              style: {
                whiteSpace: 'normal',
              },
            }
          },
        },
        {
          title: this.$t('订单类型'),
          align: 'center',
          sorter: true,
          dataIndex: 'orderType_dictText',
          width: 96,
        },
        {
          title: this.$t('会员手机号'),
          align: 'center',
          dataIndex: 'memberPhone',
          width: 100,
        },
        {
          title: this.$t('卡号'),
          align: 'center',
          dataIndex: 'cardSn',
          width: 96,
        },
        {
          title: this.$t('邮箱'),
          align: 'center',
          dataIndex: 'email',
          width: 160,
        },
        {
          title: this.$t('会员姓名'),
          align: 'center',
          dataIndex: 'memberName',
          width: 96,
          customCell: (r, i) => {
            return {
              style: {
                whiteSpace: 'normal',
              },
            }
          },
        },
        {
          title: this.$t('支付方式'),
          align: 'center',
          dataIndex: 'payType_dictText',
          width: 130,
          customCell: (r, i) => {
            return {
              style: {
                whiteSpace: 'normal',
              },
            }
          },
        },
        {
          title: this.$t('订单金额'),
          align: 'center',
          sorter: true,
          dataIndex: 'price',
          customRender: (text, record) => {
            return record.price.toFixed(2)
          },
          width: 96,
          customCell: (r, i) => {
            return {
              style: {
                whiteSpace: 'normal',
                textAlign: 'right',
              },
            }
          },
        },
        {
          title: this.$t('优惠券抵扣'),
          align: 'center',
          sorter: true,
          dataIndex: 'discountAmount',
          customRender: (text, record) => {
            return record.discountAmount.toFixed(2)
          },
          width: 156,
          customCell: (r, i) => {
            return {
              style: {
                whiteSpace: 'normal',
                textAlign: 'right',
              },
            }
          },
        },
        {
          title: this.$t('会员优惠'),
          align: 'center',
          sorter: true,
          dataIndex: 'memberDiscount',
          customRender: (text, record) => {
            return record.memberDiscount.toFixed(2)
          },
          width: 160,
          customCell: (r, i) => {
            return {
              style: {
                whiteSpace: 'normal',
                textAlign: 'right',
              },
            }
          },
        },
        {
          title: this.$t('活动优惠'),
          align: 'center',
          sorter: true,
          dataIndex: 'activityDiscount',
          customRender: (text, record) => {
            return record.activityDiscount.toFixed(2)
          },
          width: 160,
          customCell: (r, i) => {
            return {
              style: {
                whiteSpace: 'normal',
                textAlign: 'right',
              },
            }
          },
        },
        {
          title: this.$t('实付金额'),
          align: 'center',
          sorter: true,
          dataIndex: 'payAmount',
          customRender: (text, record) => {
            return record.payAmount.toFixed(2)
          },
          width: 96,
          customCell: (r, i) => {
            return {
              style: {
                whiteSpace: 'normal',
                textAlign: 'right',
              },
            }
          },
        },
        {
          title: this.$t('订单状态'),
          align: 'center',
          sorter: true,
          dataIndex: 'state_dictText',
          width: 96,
          customCell: (r, i) => {
            return {
              style: {
                whiteSpace: 'normal',
              },
            }
          },
        },
        {
          title: this.$t('业务渠道'),
          align: 'center',
          sorter: true,
          dataIndex: 'deviceType_dictText',
          width: 110,
          customCell: (r, i) => {
            return {
              style: {
                whiteSpace: 'normal',
              },
            }
          },
        },
        {
          title: this.$t('设备名称'),
          align: 'center',
          sorter: true,
          dataIndex: 'deviceName',
          width: 124,
          customCell: (r, i) => {
            return {
              style: {
                whiteSpace: 'normal',
              },
            }
          },
        },
        {
          title: this.$t('设备编码'),
          align: 'center',
          sorter: true,
          dataIndex: 'deviceId',
          width: 116,
          customCell: (r, i) => {
            return {
              style: {
                whiteSpace: 'normal',
              },
            }
          },
        },
        {
          title: this.$t('操作员'),
          align: 'center',
          sorter: true,
          dataIndex: 'createBy',
          width: 100,
          customCell: (r, i) => {
            return {
              style: {
                whiteSpace: 'normal',
              },
            }
          },
        },
        {
          title: this.$t('关联订单号'),
          align: 'center',
          dataIndex: 'subOrderId',
          width: 170,
        },
        {
          title: this.$t('操作'),
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 80,
          scopedSlots: { customRender: 'action' },
        },
      ],
      url: {
        list: '/order/bisOrder/list',
        delete: '/order/bisOrder/delete',
        deleteBatch: '/order/bisOrder/deleteBatch',
        exportXlsUrl: '/order/bisOrder/exportXls',
        totalUrl: '/order/bisOrder/total',
      },
      dictOptions: {
        payType: [],
      },
      paytypeList: [],
      orderstateList: [],
      deviceinfoList: [],
      deviceList: [],
      userList: [],
      shops: [],
      selectedRowKeys: [],
      selectionRows: [],
      batchList: [],
      isfooter: true,
      isCustom: true,
      isHideData: false,
      hideCond: 2,
      isTax: localStorage.getItem('taxSetting'),
      visible0: false,
    }
  },
  created() {
    if (!this.tenantid) {
      let dtl = {
          title: this.$t('门店编码'),
          align: 'center',
          dataIndex: 'shopCode',
          sorter: true,
          width: 96,
          customCell: (r, i) => {
            return {
              style: {
                whiteSpace: 'normal',
              },
            }
          },
        },
        dtl1 = {
          title: this.$t('门店名称'),
          align: 'center',
          dataIndex: 'shopCode_dictText',
          sorter: true,
          width: 100,
          customCell: (r, i) => {
            return {
              style: {
                whiteSpace: 'normal',
              },
            }
          },
        }
      this.defColumns.unshift(dtl1)
      this.defColumns.unshift(dtl)
    } else {
      this.isTax = localStorage.getItem('taxSetting')
      if (this.isTax != 0) {
        this.defColumns.splice(11, 0, {
          title: this.$t('其中税费'),
          align: 'center',
          dataIndex: 'taxPrice',
          sorter: true,
          width: 100,
          customRender: (text, record) => {
            return record.taxPrice.toFixed(2)
          },
          customCell: (r, i) => {
            return {
              style: {
                whiteSpace: 'normal',
                textAlign: 'right',
              },
            }
          },
        })
      }
    } 
    this.initColumns()
  },
  mounted() {
    let that = this
    document.onkeydown = function (e) {
      let key = window.event.keyCode
      if (key == 75 && event.ctrlKey) {
        window.event.preventDefault()
        that.isHideData = false
        that.queryParam.dataType = 0
        that.searchQuery()
      }
    }
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
  },
  watch: {
    '$route': {
      handler: function (to, from) {
        if (to.path === this.$route.path) {
          this.defColumns = [
            {
              title: this.$t('订单号'),
              align: 'center',
              sorter: true,
              dataIndex: 'id',
              width: 170,
            },
            {
              title: this.$t('订单时间'),
              align: 'center',
              sorter: true,
              dataIndex: 'createTime',
              width: 150,
              customCell: (r, i) => {
                return {
                  style: {
                    whiteSpace: 'normal',
                  },
                }
              },
            },
            {
              title: this.$t('订单类型'),
              align: 'center',
              sorter: true,
              dataIndex: 'orderType_dictText',
              width: 96,
            },
            {
              title: this.$t('会员手机号'),
              align: 'center',
              dataIndex: 'memberPhone',
              width: 100,
            },
            {
              title: this.$t('卡号'),
              align: 'center',
              dataIndex: 'cardSn',
              width: 96,
            },
            {
              title: this.$t('会员姓名'),
              align: 'center',
              dataIndex: 'memberName',
              width: 96,
              customCell: (r, i) => {
                return {
                  style: {
                    whiteSpace: 'normal',
                  },
                }
              },
            },
            {
              title: this.$t('支付方式'),
              align: 'center',
              dataIndex: 'payType_dictText',
              width: 130,
              customCell: (r, i) => {
                return {
                  style: {
                    whiteSpace: 'normal',
                  },
                }
              },
            },
            {
              title: this.$t('订单金额'),
              align: 'center',
              sorter: true,
              dataIndex: 'price',
              customRender: (text, record) => {
                return record.price.toFixed(2)
              },
              width: 96,
              customCell: (r, i) => {
                return {
                  style: {
                    whiteSpace: 'normal',
                    textAlign: 'right',
                  },
                }
              },
            },
            {
              title: this.$t('优惠券抵扣'),
              align: 'center',
              sorter: true,
              dataIndex: 'discountAmount',
              customRender: (text, record) => {
                return record.discountAmount.toFixed(2)
              },
              width: 156,
              customCell: (r, i) => {
                return {
                  style: {
                    whiteSpace: 'normal',
                    textAlign: 'right',
                  },
                }
              },
            },
            {
              title: this.$t('会员优惠'),
              align: 'center',
              sorter: true,
              dataIndex: 'memberDiscount',
              customRender: (text, record) => {
                return record.memberDiscount.toFixed(2)
              },
              width: 160,
              customCell: (r, i) => {
                return {
                  style: {
                    whiteSpace: 'normal',
                    textAlign: 'right',
                  },
                }
              },
            },
            {
              title: this.$t('活动优惠'),
              align: 'center',
              sorter: true,
              dataIndex: 'activityDiscount',
              customRender: (text, record) => {
                return record.activityDiscount.toFixed(2)
              },
              width: 160,
              customCell: (r, i) => {
                return {
                  style: {
                    whiteSpace: 'normal',
                    textAlign: 'right',
                  },
                }
              },
            },
            {
              title: this.$t('实付金额'),
              align: 'center',
              sorter: true,
              dataIndex: 'payAmount',
              customRender: (text, record) => {
                return record.payAmount.toFixed(2)
              },
              width: 96,
              customCell: (r, i) => {
                return {
                  style: {
                    whiteSpace: 'normal',
                    textAlign: 'right',
                  },
                }
              },
            },
            {
              title: this.$t('订单状态'),
              align: 'center',
              sorter: true,
              dataIndex: 'state_dictText',
              width: 96,
              customCell: (r, i) => {
                return {
                  style: {
                    whiteSpace: 'normal',
                  },
                }
              },
            },
            {
              title: this.$t('业务渠道'),
              align: 'center',
              sorter: true,
              dataIndex: 'deviceType_dictText',
              width: 110,
              customCell: (r, i) => {
                return {
                  style: {
                    whiteSpace: 'normal',
                  },
                }
              },
            },
            {
              title: this.$t('设备名称'),
              align: 'center',
              sorter: true,
              dataIndex: 'deviceName',
              width: 124,
              customCell: (r, i) => {
                return {
                  style: {
                    whiteSpace: 'normal',
                  },
                }
              },
            },
            {
              title: this.$t('设备编码'),
              align: 'center',
              sorter: true,
              dataIndex: 'deviceId',
              width: 116,
              customCell: (r, i) => {
                return {
                  style: {
                    whiteSpace: 'normal',
                  },
                }
              },
            },
            {
              title: this.$t('操作员'),
              align: 'center',
              sorter: true,
              dataIndex: 'createBy',
              width: 100,
              customCell: (r, i) => {
                return {
                  style: {
                    whiteSpace: 'normal',
                  },
                }
              },
            },
            {
              title: this.$t('关联订单号'),
              align: 'center',
              dataIndex: 'subOrderId',
              width: 170,
            },
            {
              title: this.$t('操作'),
              dataIndex: 'action',
              align: 'center',
              fixed: 'right',
              width: 80,
              scopedSlots: { customRender: 'action' },
            },
          ]
          if (!this.tenantid) {
            let dtl = {
                title: this.$t('门店编码'),
                align: 'center',
                dataIndex: 'shopCode',
                sorter: true,
                width: 96,
                customCell: (r, i) => {
                  return {
                    style: {
                      whiteSpace: 'normal',
                    },
                  }
                },
              },
              dtl1 = {
                title: this.$t('门店名称'),
                align: 'center',
                dataIndex: 'shopCode_dictText',
                sorter: true,
                width: 100,
                customCell: (r, i) => {
                  return {
                    style: {
                      whiteSpace: 'normal',
                    },
                  }
                },
              }
            this.defColumns.unshift(dtl1)
            this.defColumns.unshift(dtl)
          } else {
            this.isTax = localStorage.getItem('taxSetting')
            if (this.isTax != 0) {
              this.defColumns.splice(11, 0, {
                title: this.$t('其中税费'),
                align: 'center',
                dataIndex: 'taxPrice',
                sorter: true,
                width: 100,
                customRender: (text, record) => {
                  return record.taxPrice
                },
                customCell: (r, i) => {
                  return {
                    style: {
                      whiteSpace: 'normal',
                      textAlign: 'right',
                    },
                  }
                },
              })
            }
          }
          this.$forceUpdate()
          this.initColumns()
        }
      },
      // 设置为深度监听
      deep: true,
    },
  },
  methods: {
    initDictConfig() {
      this.customInit()
      let param = {}
      param.pageNo = 1
      param.pageSize = 9999
      param.orderType = 0
      getAction('/pay/bisPayType/list', param).then((res) => {
        if (res.success) {
          let list = []
          let arr = res.result.records
            .filter((rds) => {
              return (
                rds.state == 'Y' && rds.name != 6 && rds.name != 7 && rds.name != 10 && rds.name != 11 && rds.name != 12
              )
            })
            .filter((item) => {
              return !list.includes(item.name) && list.push(item.name)
            })
          this.paytypeList = arr
          this.paytypeList.unshift({ name: '', nameText: this.$t('全部') })
        }
      })
      initDictOptions('bis_order.state').then((res) => {
        if (res.success) {
          this.orderstateList = res.result
          this.orderstateList.unshift({ value: '', title: this.$t('全部') })
        }
      })
      initDictOptions('bis_device_info.type').then((res) => {
        if (res.success) {
          this.deviceinfoList = res.result
          this.deviceinfoList.unshift({ value: '', title: this.$t('全部') })
        }
      })
      initDictOptions('bis_shop,name,code').then((res) => {
        if (res.success) {
          this.shops = res.result
          this.shops.unshift({ value: '', title: this.$t('全部') })
        }
      })
      getAction('/sys/user/list').then((res) => {
        if (res.success) {
          this.userList = res.result.records
          this.userList.forEach((col) => {
            col.id = col.realname
          })
          this.userList.unshift({ id: '', realname: this.$t('全部') })
        }
      })
    },
    customInit() {
      this.handleSearch('')
      this.isHideData = true
      this.queryParam.dataType = 2
      this.loadData(1)
    },
    handleSearch(value) {
      let query = {}
      if (value) {
        query.deviceInfo = value
      }
      getAction('/device/bisDeviceInfo/list', query).then((res) => {
        if (res.success) {
          this.deviceList = res.result.records
          this.deviceList.unshift({ id: '', name: this.$t('全部') })
        }
      })
    },
    handleDelete: function (id) {
      //认证
      let param= {id:id};
      var that = this;
      that.$refs.deleteYarnModal.show(param);
    },
    handleDeleteCallback: function (result) {
      let that = this
      var deleteUrl
      let query={}
      query.captcha=result.captcha
      if(result.id.includes(',')) {
        deleteUrl = that.url.deleteBatch
        query.ids=result.id
      }else {
        deleteUrl = that.url.delete
        query.id=result.id
      }
      deleteAction(deleteUrl, query).then((res) => {
        if (res.success) {
          //重新计算分页问题
          that.reCalculatePage(1)
          that.$message.success(res.message);
          that.$refs.deleteYarnModal.close();
          that.loadData();
          that.batchList = []
          if (that.delCallback != null && that.delCallback != undefined) {
            that.delCallback(arg);
          }
        } else {
          that.$message.warning(res.message);
        }
      });
    },
    handleClick() {
      if(this.batchList.length>0){
        this.visible0 = true;
      }else{
        this.$message.warning(this.$t('请选择要删除的订单'))
      }
    },
    deleteBatch() {
      if (this.batchList.length > 0) {
        const ids = this.batchList.join(',')
        //认证
        let param= {id:ids};
        var that = this;
        that.$refs.deleteYarnModal.show(param);
        that.visible0 = false
      }
    },
    //列设置更改事件
    onColSettingsChange(checkedValues) {
      var key = this.$route.name + ':colsettings'
      Vue.ls.set(key, checkedValues, 7 * 24 * 60 * 60 * 1000)
      this.settingColumns = checkedValues
      const cols = this.defColumns.filter((item) => {
        if (item.key == 'rowIndex' || item.dataIndex == 'action') {
          return true
        }
        if (this.settingColumns.includes(item.dataIndex)) {
          return true
        }
        return false
      })
      this.columns = cols
    },
    searchReset() {
      this.queryParam = {
        createTime_begin: '',
        createTime_end: '',
        payType: '',
        orderInfo: '',
        state: '2',
        deviceType: '',
        deviceId: '',
        createBy: '',
        orderType: '0,2,4,8,6,10,11,12',
        shopCode: '',
      }
      this.selectedRowIndex = []
      this.customInit()
    },
    onSelectChange(selectedRowKeys, selectionRows) {
      this.selectedRowKeys = selectedRowKeys
      this.selectionRows = selectionRows
      this.batchList = []
      selectionRows.forEach((row) => {
        this.batchList.push(row.id)
      })
    },
    onClearSelected() {
      this.selectedRowKeys = []
      this.selectionRows = []
    },
    initColumns() {
      //权限过滤（列权限控制时打开，修改第二个参数为授权码前缀）
      //this.defColumns = colAuthFilter(this.defColumns,'testdemo:');
      var key = this.$route.name + ':colsettings'
      let colSettings = Vue.ls.get(key)
      if (colSettings == null || colSettings == undefined) {
        let allSettingColumns = []
        this.defColumns.forEach(function (item, i, array) {
          allSettingColumns.push(item.dataIndex)
        })
        this.settingColumns = allSettingColumns
        this.columns = this.defColumns
      } else {
        this.settingColumns = colSettings
        const cols = this.defColumns.filter((item) => {
          if (item.key == 'rowIndex' || item.dataIndex == 'action') {
            return true
          }
          if (colSettings.includes(item.dataIndex)) {
            return true
          }
          return false
        })
        this.columns = cols
      }
    },
    showModal(record) {
      this.$refs.typeNameForm.edit(record)
    },
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>